encyclopediafandomcom_bn-20200215-history
মডিউল:Coordinates
বাংলায় ঠিক মত ফলাফল দেয়ার জন্য এখানে কিছু পরিবর্তন করা হয়েছে। এটি হালনাগাদ করার সময় অবশ্যই সতর্কতা অবলম্বন করুন। -- coord }} : General function formatting and displaying coordinate values. : Simple function for converting decimal degree values to DMS format. : Simple function for converting DMS format to decimal degree format. : Export the link used to reach the tools local math_mod = require( "Module:Math" ); local convert = require( "Module:Numeral converter" ).convert; local globalFrame = nil local coordinates = {}; local current_page = mw.title.getCurrentTitle() local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' ); local coord_link = '//tools.wmflabs.org/geohack/geohack.php?language=bn&pagename=' .. page_name .. '&params=' -- Helper function, replacement for local function displaytitle (s, notes) local l = "স্থানাঙ্ক: " .. s local co = '' .. l .. notes .. ''; return '' .. co .. ''; end -- Helper function, Replacement for local function displayinline (s, notes) return s .. notes end -- Helper function, used in detecting DMS formatting local function dmsTest (first, second) local concatenated = first:upper() .. second:upper(); if concatenated "NE" or concatenated "NW" or concatenated "SE" or concatenated "SW" or concatenated "EN" or concatenated "WN" or concatenated "ES" or concatenated "WS" then return true; end return false; end -- Helper function, handle optional args. local function optionalArg(arg, suplement) if arg ~= nil and arg ~= "" then return arg .. suplement end return "" end -- Formats any error messages generated for display local function errorPrinter(errors) local result = "" for i,v in ipairs(errors) do local errorHTML = 'স্থানাঙ্ক: ' .. v2 .. '' result = result .. errorHTML .. " " end return result end -- Determine the required CSS class to display coordinates Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himself default is the mode as specificied by the user when calling the template mode is the display mode (dec or dms) that we will need to determine the css class for local function displayDefault(default, mode) if default "" then default = "dec" end if default mode then return "geo-default" else return "geo-nondefault" end end -- specPrinter Output formatter. Takes the structure generated by either parseDec or parseDMS and formats it for inclusion on Wikipedia. local function specPrinter(args, coordinateSpec) local uriComponents = coordinateSpec"param" if uriComponents "" then -- RETURN error, should never be empty or nil return "ত্রুটি: প্যারামিটার খালি" end if args"name" ~= "" and args"name" ~= nil then uriComponents = uriComponents .. "&title=" .. mw.uri.encode(coordinateSpec"name") end local geodmshtml = '' .. '' .. convert("bn", coordinateSpec"dms-lat") .. ' ' .. '' .. convert("bn", coordinateSpec"dms-long") .. '' .. '' local lat = tonumber( coordinateSpec"dec-lat" ) or 0 local geodeclat if lat < 0 then -- FIXME this breaks the pre-existing precision geodeclat = '' .. coordinateSpec"dec-lat":sub(2) .. "° দক্ষিণ" else geodeclat = '' .. (coordinateSpec"dec-lat" or 0) .. "° উত্তর" end local long = tonumber( coordinateSpec"dec-long" ) or 0 local geodeclong if long < 0 then -- FIXME does not handle unicode minus geodeclong = '' .. coordinateSpec"dec-long":sub(2) .. "° পশ্চিম" else geodeclong = '' .. (coordinateSpec"dec-long" or 0) .. "° পূর্ব" end local geodechtml = '' .. convert("bn", geodeclat) .. ' ' .. convert("bn", geodeclong) .. '' local geonumhtml = '' .. coordinateSpec"dec-lat" .. '; ' .. coordinateSpec"dec-long" .. '' local inner = '' .. geodmshtml .. '' .. '﻿ / ﻿' .. ''; if args"name" "" or args"name" nil then inner = inner .. geodechtml .. '﻿ / ' .. geonumhtml .. '' else inner = inner .. '' .. geodechtml .. '﻿ / ' .. geonumhtml .. '' .. '﻿ (' .. args"name" .. ')' end return '' .. '.. coord_link .. uriComponents .. ' ' .. inner .. '' .. '' end -- Helper function, convert decimal to degrees local function convert_dec2dms_d(coordinate) local d = '' .. math_mod._round( coordinate, 0 ) .. "°" .. '' return d .. "" end -- Helper function, convert decimal to degrees and minutes local function convert_dec2dms_dm(coordinate) coordinate = math_mod._round( coordinate * 60, 0 ); local m = coordinate % 60; coordinate = math.floor( (coordinate - m) / 60 ); local d = '' .. coordinate % 360 .."°" .. '' return d .. string.format( '%02d′', m ) end -- Helper function, convert decimal to degrees, minutes, and seconds local function convert_dec2dms_dms(coordinate) coordinate = math_mod._round( coordinate * 60 * 60, 0 ); local s = coordinate % 60 coordinate = math.floor( (coordinate - s) / 60 ); local m = coordinate % 60 coordinate = math.floor( (coordinate - m) / 60 ); local d = '' .. coordinate % 360 .."°" .. '' return d .. string.format( '%02d′', m ) .. string.format( '%02d″', s ) end -- Helper function, convert decimal latitude or longitude to degrees, minutes, and seconds format based on the specified precision. local function convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision) local coord = tonumber(coordinate) local postfix if coord >= 0 then postfix = firstPostfix else postfix = secondPostfix end precision = precision:lower(); if precision "dms" then return convert_dec2dms_dms( math.abs( coord ) ) .. postfix; elseif precision "dm" then return convert_dec2dms_dm( math.abs( coord ) ) .. postfix; elseif precision "d" then return convert_dec2dms_d( math.abs( coord ) ) .. postfix; end end -- Convert DMS format into a N or E decimal coordinate local function convert_dms2dec(direction, degrees_str, minutes_str, seconds_str) local degrees = tonumber(degrees_str) local minutes = tonumber(minutes_str) or 0 local seconds = tonumber(seconds_str) or 0 local factor = 1 direction = direction:gsub('^ *(.-) *$', '%1'); if direction "S" or direction "W" then factor = -1 end local precision = 0 if seconds_str ~= nil and seconds_str ~= '' then precision = 5 + math.max( math_mod._precision(seconds_str), 0 ); elseif minutes_str ~= nil and minutes_str ~= '' then precision = 3 + math.max( math_mod._precision(minutes_str), 0 ); else precision = math.max( math_mod._precision(degrees_str), 0 ); end local decimal = factor * (degrees+(minutes+seconds/60)/60) return string.format( "%." .. precision .. "f", decimal ) -- not tonumber since this whole thing is string based. end